﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace S2_Xxxx_XxxNetApi
{
    public static class ArrayCommon
    {
        /// <summary>
        /// 添加一条数据到数组
        /// </summary>
        /// <param name="arr"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public static int[] Add(this int[] arr, int item)
        {
            int[] _arr = new int[arr.Length + 1];
            arr.CopyTo(_arr, 0);
            _arr[arr.Length] = item;
            return _arr;
        }

        /// <summary>
        /// 添加一条数据到数组
        /// </summary>
        /// <param name="motherarray"></param>
        /// <param name="arr"></param>
        /// <returns></returns>
        public static int[][] Add(this int[][] motherarray, int[] arr)
        {
            int[][] _arr = new int[motherarray.Length + 1][];
            motherarray.CopyTo(_arr, 0);
            _arr[motherarray.Length] = arr;
            return _arr;
        }

        /// <summary>
        /// 添加一条数据到数组
        /// </summary>
        /// <param name="arr"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public static string[] Add(this string[] arr, string item)
         {
             string[] _arr = new string[arr.Length + 1];
             arr.CopyTo(_arr, 0);
             _arr[arr.Length] = item;
             return _arr;
         }

        /// <summary>
        /// 添加一条数据到数组
        /// </summary>
        /// <param name="motherarray"></param>
        /// <param name="arr"></param>
        /// <returns></returns>
        public static string[][] Add(this string[][] motherarray, string[] arr)
         {
             string[][] _arr = new string[motherarray.Length + 1][];
             motherarray.CopyTo(_arr, 0);
             _arr[motherarray.Length] = arr;
             return _arr;
         }

         /// <summary>
         /// 去除数组中指定的项
        /// </summary>
         /// <param name="arr">一个字符串数组</param>
         /// <param name="index">索引项</param>
         /// <returns></returns>
         public static string[] RemoveAt(string[] arr, int index)
         {
             if (index >= arr.Length || index < 0)
             {
                 return arr;
             }
             else
             {
                 string[] newarr = new string[arr.Length - 1];
                 Array.Copy(arr, 0, newarr, 0, index);
                 Array.Copy(arr, index + 1, newarr, index, newarr.Length - index);
                 return newarr;
             }
         }

        /// <summary>
         /// 去除数组中指定的项
        /// </summary>
         /// <param name="arr">一个数字数组</param>
         /// <param name="index">索引项</param>
         /// <returns></returns>
         public static int[] RemoveAt(int[] arr, int index)
         {
             if (index >= arr.Length || index < 0)
             {
                 return arr;
             }
             else
             {
                 int[] newarr = new int[arr.Length - 1];
                 Array.Copy(arr, 0, newarr, 0, index);
                 Array.Copy(arr, index + 1, newarr, index, newarr.Length - index);
                 return newarr;
             }
         }
    }
}
